package com.lsa.letcode.the26.removeDuplicatesFromSrt;

public class Solution {
	public int removeDuplicates(int[] arr) {
		int[] pLen = {0};
		removeDuplicatesArr(arr, pLen);
		return pLen[0];
	}
	
	public int[] removeDuplicatesArr(int[] arr, int[] pLen) {
		if (arr == null) {
			pLen[0] = 0;
			return arr;
		}
		if (arr.length < 2) {
			pLen[0] = arr.length;
			return arr;
		}
		int prev = arr[0];
		int pos = 0;
		
		for (int i = 1; i < arr.length; i++) {
			int n = arr[i];
			if (prev != n) {
				arr[++pos] = n;
				prev = n;
			}
		}
		
		pLen[0] = pos + 1;
		return arr;
	}
}